<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv=X-UA-Compatible content=IE=EmulateIE7>
  <meta http-equiv=X-UA-Compatible content=IE=7>
  <meta http-equiv="Content-Language" content="zh-cn">
  <title>CC301 pstn二次开发演示1.2</title>
  <script src="callphone/jquery-1.8.3.min.js"></script>
  <script src="callphone/qnviccub.js"></script>
  <script src="callphone/qnvfunc.js"></script>
</head>
<script language=javascript>
  var DailLoaded = false;
  var DailEnded = false;
  function AppendStatus(szStatus)
  {
    // qnviccub.QNV_Tool(QNV_TOOL_WRITELOG,0,szStatus,NULL,NULL,0);//写本地日志到控件注册目录的userlog目录下
    // var szHint = $("#StatusArea").val()+ szStatus +"\r\n";
    $("#callMessage").append("<li>" + szStatus +"</li>");
    // $("#StatusArea").val(szHint);
    // $("#StatusArea").scrollTop($("#StatusArea").scrollHeight());
  }
  function AppendStatusEx(uID,szStatus)
  {
    uID=uID+1;
    AppendStatus("通道"+uID+":"+szStatus);
  }

  function  T_GetEvent(uID,uEventType,uHandle,uResult,szdata)
  {
    //var vValueArray=qnviccub.QNV_Event(0,2,0,"","",1024);
    var vValue=" type="+uEventType+" Handle="+uHandle+" Result="+uResult+" szdata="+szdata;
    switch(uEventType)
    {
      case BriEvent_PhoneHook:// 本地电话机摘机事件
        AppendStatusEx(uID,"本地电话机摘机"+vValue);
        break;
      case BriEvent_PhoneDial:// 只有在本地话机摘机，没有调用软摘机时，检测到DTMF拨号
        AppendStatusEx(uID,"本地话机拨号"+vValue);
        break;
      case BriEvent_PhoneHang:// 本地电话机挂机事件
        AppendStatusEx(uID,"本地电话机挂机"+vValue);
        break;
      case BriEvent_CallIn:// 外线通道来电响铃事件
        AppendStatusEx(uID,"外线通道来电响铃事件"+vValue);
        break;
      case BriEvent_GetCallID://得到来电号码
        AppendStatusEx(uID,"得到来电号码"+vValue);
        break;
      case BriEvent_StopCallIn:// 对方停止呼叫(产生一个未接电话)
        AppendStatusEx(uID,"对方停止呼叫(产生一个未接电话)"+vValue);
        break;
      case BriEvent_DialEnd:// 调用开始拨号后，全部号码拨号结束
        AppendStatusEx(uID,"调用开始拨号后，全部号码拨号结束"+vValue);
        break;
      case BriEvent_PlayFileEnd:// 播放文件结束事件
        AppendStatusEx(uID,"播放文件结束事件"+vValue);
        break;
      case BriEvent_PlayMultiFileEnd:// 多文件连播结束事件
        AppendStatusEx(uID,"多文件连播结束事件"+vValue);
        break;
      case BriEvent_PlayStringEnd://播放字符结束
        AppendStatusEx(uID,"播放字符结束"+vValue);
        break
      case BriEvent_RepeatPlayFile:// 播放文件结束准备重复播放
        AppendStatusEx(uID,"播放文件结束准备重复播放"+vValue);
        break;
      case BriEvent_SendCallIDEnd:// 给本地设备发送震铃信号时发送号码结束
        AppendStatusEx(uID,"给本地设备发送震铃信号时发送号码结束"+vValue);
        break;
      case BriEvent_RingTimeOut://给本地设备发送震铃信号时超时
        AppendStatusEx(uID,"给本地设备发送震铃信号时超时"+vValue);
        break;
      case BriEvent_Ringing://正在内线震铃
        AppendStatusEx(uID,"正在内线震铃"+vValue);
        break;
      case BriEvent_Silence:// 通话时检测到一定时间的静音.默认为5秒
        AppendStatusEx(uID,"通话时检测到一定时间的静音"+vValue);
        break;
      case BriEvent_GetDTMFChar:// 线路接通时收到DTMF码事件
        AppendStatusEx(uID,"线路接通时收到DTMF码事件"+vValue);
        break;
      case BriEvent_RemoteHook:// 拨号后,被叫方摘机事件
        AppendStatusEx(uID,"拨号后,被叫方摘机事件"+vValue);
        if (!DailLoaded) {
          // 接通操作提示
          AppendStatusEx(uID,'电话已经接通');
          // 开始录音
          TV_StartRecordFileAuto(0, 0);
          DailLoaded = true;
        }
        break;
      case BriEvent_RemoteHang://对方挂机事件
        AppendStatusEx(uID,"对方挂机事件"+vValue);
        if (!DailEnded) {
          // 结束拨号
          TV_HangUpCtrl(0);
          // 关闭mic
          TV_EnableMic(0, FALSE);
          // 关闭耳机
          TV_EnableLine2Spk(0, FALSE);
          // 结束录音
          TV_StopRecordFileAuto(0);
          AppendStatusEx(uID,"通话已结束");
          DailEnded = true;
        }
        break;
      case BriEvent_Busy:// 检测到忙音事件,表示PSTN线路已经被断开
        AppendStatusEx(uID,"检测到忙音事件,表示PSTN线路已经被断开"+vValue);
        break;
      case BriEvent_DialTone:// 本地摘机后检测到拨号音
        AppendStatusEx(uID,"本地摘机后检测到拨号音"+vValue);
        break;
      case BriEvent_RingBack:// 电话机拨号结束呼出事件。
        AppendStatusEx(uID,"电话机拨号结束呼出事件"+vValue);
        break;
      case BriEvent_MicIn:// MIC插入状态
        AppendStatusEx(uID,"MIC插入状态"+vValue);
        break;
      case BriEvent_MicOut:// MIC拔出状态
        AppendStatusEx(uID,"MIC拔出状态"+vValue);
        break;
      case BriEvent_FlashEnd:// 拍插簧(Flash)完成事件，拍插簧完成后可以检测拨号音后进行二次拨号
        AppendStatusEx(uID,"拍插簧(Flash)完成事件，拍插簧完成后可以检测拨号音后进行二次拨号"+vValue);
        break;
      case BriEvent_RefuseEnd:// 拒接完成
        AppendStatusEx(uID,"拒接完成"+vValue);
        break;
      case BriEvent_SpeechResult:// 语音识别完成
        AppendStatusEx(uID,"语音识别完成"+vValue);
        break;
      case BriEvent_FaxRecvFinished:// 接收传真完成
        AppendStatusEx(uID,"接收传真完成"+vValue);
        break;
      case BriEvent_FaxRecvFailed:// 接收传真失败
        AppendStatusEx(uID,"接收传真失败"+vValue);
        break;
      case BriEvent_FaxSendFinished:// 发送传真完成
        AppendStatusEx(uID,"发送传真完成"+vValue);
        break;
      case BriEvent_FaxSendFailed:// 发送传真失败
        AppendStatusEx(uID,"发送传真失败"+vValue);
        break;
      case BriEvent_OpenSoundFailed:// 启动声卡失败
        AppendStatusEx(uID,"启动声卡失败"+vValue);
        break;
      case BriEvent_UploadSuccess://远程上传成功
        AppendStatusEx(uID,"远程上传成功"+vValue);
        break;
      case BriEvent_UploadFailed://远程上传失败
        AppendStatusEx(uID,"远程上传失败"+vValue);
        break;
      case BriEvent_EnableHook:// 应用层调用软摘机/软挂机成功事件
        AppendStatusEx(uID,"应用层调用软摘机/软挂机成功事件"+vValue);
        break;
      case BriEvent_EnablePlay:// 喇叭被打开或者/关闭
        AppendStatusEx(uID,"喇叭被打开或者/关闭"+vValue);
        break;
      case BriEvent_EnableMic:// MIC被打开或者关闭
        AppendStatusEx(uID,"MIC被打开或者关闭"+vValue);
        break;
      case BriEvent_EnableSpk:// 耳机被打开或者关闭
        AppendStatusEx(uID,"耳机被打开或者关闭"+vValue);
        break;
      case BriEvent_EnableRing:// 电话机跟电话线(PSTN)断开/接通
        AppendStatusEx(uID,"电话机跟电话线(PSTN)断开/接通"+vValue);
        break;
      case BriEvent_DoRecSource:// 修改录音源
        AppendStatusEx(uID,"修改录音源"+vValue);
        break;
      case BriEvent_DoStartDial:// 开始软件拨号
        AppendStatusEx(uID,"开始软件拨号"+vValue);
        break;
      case BriEvent_RecvedFSK:// 接收到FSK信号，包括通话中FSK/来电号码的FSK
        AppendStatusEx(uID,"接收到FSK信号，包括通话中FSK/来电号码的FSK"+vValue);
        break;
      case BriEvent_DevErr://设备错误
        AppendStatusEx(uID,"设备错误"+vValue);
        break;
      default:
        if(uEventType < BriEvent_EndID){
          AppendStatusEx(uID, '忽略其它事件发生:ID=' + uEventType + vValue);
        }
        break;
    }
  }
</script>
<body onload="TV_Initialize()" onUnload="TV_Disable()">
<SCRIPT LANGUAGE="JavaScript" FOR="qnviccub" EVENT="OnQnvEvent(chID,type,handle,result,param,szdata,szdataex)">
  T_GetEvent(chID,type,handle,result,szdata)
</SCRIPT>
<p>
  当前主页面：
</p>
<p>
  <ul id="callMessage">
    <!--<li>开始拨号中....</li>-->
  </ul>
<!--<input type="button" value="上传附件" name="B123" onClick="uploadRecord()">-->
</p>
<p>
  <!--<textarea id="StatusArea" rows="13" name="S1" cols="86"></textarea>-->
  <object classid="clsid:F44CFA19-6B43-45EE-90A3-29AA08000510" id="qnviccub" data="DATA:application/x-oleobject;BASE64,GfpM9ENr7kWQoymqCAAFEAADAAD7FAAADhEAAA==
" width="0" height="0"></object>
  <!--<input type="button" value="检查控件是否安装" name="B0" onClick="I_CheckActiveX()">-->
</p>
<!--<p>-->
  <!--<input type="button" value="打开设备" name="B3" onClick="TV_Initialize()">-->
  <!--<input type="button" value="关闭设备" name="B6" onClick="TV_Disable()">&nbsp;&nbsp;&nbsp;-->
  <!--<input type="button" value="播放文件" name="B13" onClick="TV_StartPlayFile(0,0)">-->
  <!--<input type="button" value="停止播放" name="B14" onClick="TV_StopPlayFile(0)">&nbsp;&nbsp;&nbsp;-->
  <!--<input type="button" value="开始录音" name="B15" onClick="TV_StartRecordFile(0,0)">-->
  <!--<input type="button" value="停止录音" name="B16" onClick="TV_StopRecordFile(0)">-->
  <!--<input type="button" value="删除录音" name="B26" onClick="TV_DeleteRecordFile(0)">-->
<!--</p>-->
<!--<form>-->
  <!--<p>-->
    <!--<input type="text" name="T1" size="20" id="dialcode">-->
    <!--<input type="button" value="拨号" name="B10" onClick="startCall()">-->
    <!--<input type="button" value="拨号" name="B10" onClick="TV_StartDial(0,dialcode.value)">-->
  <!--</p>-->
<!--</form>-->
<!--<p><input type="button" value="摘机" name="B7" onClick="TV_OffHookCtrl(0)">-->
  <!--<input type="button" value="挂机" name="B8" onClick="TV_HangUpCtrl(0)">-->
  <!--<input type="button" value="拒接来电" name="B24" onClick="TV_RefuseCallIn(0)">-->
  <!--<input type="button" value="拍插簧" name="B25" onClick="TV_StartFlash(0)"></p>-->
<!--<p>-->
  <!--<input type="button" value="打开MIC" name="B18" onClick="TV_EnableMic(0,TRUE)">-->
  <!--<input type="button" value="关闭MIC" name="B19" onClick="TV_EnableMic(0,FALSE)">-->
  <!--<input type="button" value="打开耳机" name="B22" onClick="TV_EnableLine2Spk(0,TRUE)">-->
  <!--<input type="button" value="关闭耳机" name="B23" onClick="TV_EnableLine2Spk(0,FALSE)">-->
  <!--<input type="button" value="打开播放文件声音到耳机" name="B22" onClick="TV_EnableMicSpk(0,TRUE)">-->
  <!--<input type="button" value="关闭播放文件声音到耳机" name="B23" onClick="TV_EnableMicSpk(0,FALSE)">&nbsp; <input type="button" value="打开喇叭" name="B11" onClick="TV_OpenDoPlay(0)">-->
  <!--<input type="button" value="关闭喇叭" name="B12" onClick="TV_CloseDoPlay(0)">-->
  <!--<input type="button" value="断开话机与电话线连接" name="B20" onClick="TV_EnableRing(0,FALSE)">-->
  <!--<input type="button" value="接通话机与电话线连接" name="B21" onClick="TV_EnableRing(0,TRUE)">-->
  <!--<input type="button" value="开始话机模拟震铃" name="B21" onClick="TV_StartRing(1,TRUE)">-->
  <!--<input type="button" value="停止话机模拟震铃" name="B21" onClick="TV_StartRing(1,FALSE)">-->
<!--</p>-->
<!--<p><input type="button" value="获取盘符列表" name="B15" onClick="TV_GetDiskList()"> <input type="button" value="选择目录" name="B17" onClick="TV_BrowerPath()"></p>-->
<!--<form>-->
  <!--<p>-->
    <!--<input type="text" name="TDISK" size="7" id="diskname" value="c:\">-->
    <!--<input type="button" value="获取硬盘空闲大小" name="C12" onClick="TV_GetFreeSpace(diskname.value)">-->
    <!--<input type="button" value="获取硬盘总共大小" name="C13" onClick="TV_GetTotalSpace(diskname.value)">-->
    <!--<input type="button" value="所有设备和声卡组成会议" name="C14" onClick="TV_StartConference()">-->
    <!--<input type="button" value="停止会议" name="C15" onClick="TV_StopConference()"></p>-->
<!--</form>-->
<!--<p></p>-->
<!--<p>-->
  <!--<input type="button" value="子窗口" name="C16" onClick="window.open('demo.htm')">-->
<!--</p>-->
</body>
<script>
  var phone;
  var filename = 'temp.wav';
  $(function () {
    phone=GetQueryString("phone");
    if(phone !=null && phone.toString().length>1)
    {
      setTimeout(startCall, 5000);
    }else {
      AppendStatus("没有号码或号码不正确，拨号失败！");
    }
  })
  function startCall() {
    TV_StartDial(0, phone)
    // 打开mic
    TV_EnableMic(0, TRUE);
    // 打开耳机
    TV_EnableLine2Spk(0, TRUE);
  }
  function GetQueryString(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return unescape(r[2]); return null;
  }
  function TV_StartRecordFileAuto(uID,szFile) {
    filename=new Date().getFullYear()+""+(new Date().getMonth()+1)+""+new Date().getDate()+"-"+phone+"-"+(Math.random().toString().slice(2,10))+".wav";
    TV_StopRecordFile(uID);
    var vFormatID=BRI_WAV_FORMAT_IMAADPCM8K4B;//选择使用4K/S的ADPCM格式录音
    var vmask=RECORD_MASK_ECHO|RECORD_MASK_AGC;//使用回音抵消后并且自动增益的数据
    uRecordID[uID]=qnviccub.QNV_RecordFile(uID,QNV_RECORD_FILE_START,vFormatID,vmask,"c:\\wav\\"+filename); //"c:\\wave\\g.wav"
    if (uRecordID[uID] <= 0) {
      AppendStatusEx(uID, "录音失败:" + filename);
    } else {
      AppendStatusEx(uID, "开始录音文件: id=" + uRecordID[uID] + "  " + filename);
    }
    return;
  }
  function uploadRecord() {
    var url='http://127.0.0.1:8088/yimi_doms/attachment/upLoadFile';
    var fullFilePath='C:\\wav\\20181026-15258823561-92267722.wav';
    qnviccub.QNV_Remote(QNV_REMOTE_UPLOAD_START,0,url,fullFilePath,0,0);
  }
  function TV_StopRecordFileAuto(uID) {
    var fullFilePath = qnviccub.QNV_RecordFile(uID, QNV_RECORD_FILE_PATH, uRecordID[uID], 0, 0);
    // recordPath = fullFilePath;
    if (!fullFilePath) {
      AppendStatusEx(uID,"录音失败。");
      return;
    }
    // alert(fullFilePath);
    TV_StopRecordFile(uID);
    // 上传录音
    qnviccub.QNV_Remote(QNV_REMOTE_UPLOAD_START,0,'http://127.0.0.1:8088/yimi_doms/attachment/upLoadFile',fullFilePath,0,0);
  }
</script>
</html>
